package com.zz.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zz.common.R;
import com.zz.dto.ActivityDto;
import com.zz.dto.BoxDto;
import com.zz.entity.Activity;
import com.zz.entity.Box;
import com.zz.entity.Club;
import com.zz.mapper.BoxMapper;
import com.zz.service.BoxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@Validated
public class BoxServiceImpl extends ServiceImpl<BoxMapper, Box> implements BoxService {

    @Autowired
    private BoxMapper boxMapper;

    /**
     * 活动投稿箱分页展示
     * 周紫
     * */
    @Override
    public R<Page> page(int page, int pageSize, @Nullable String theme, HttpServletRequest request) {

        //获取社团id
        int clubId = (int) request.getSession().getAttribute("club");
        if (clubId == 0){
            return R.error("您还未选择社团进行管理！");
        }

        // 构造分页构造器
        Page<Box> pageInfo = new Page<>(page, pageSize);

        // 构造条件构造器
        LambdaQueryWrapper<Box> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(Box::getClubId, clubId);
        queryWrapper.like(theme != null, Box::getTheme, theme);

        // 执行分页查询
        // 在page方法内部会将查好的数据封装，赋好值给pageInfo
        Page<Box> boxPage = boxMapper.selectPage(pageInfo, queryWrapper);

        return R.success(boxPage);
    }



}
